//
//  ZCToolView.swift
//  weibo
//
//  Created by 张城 on 16/7/26.
//  Copyright © 2016年 张城. All rights reserved.
//

import UIKit


enum ZCToolViewButtonType: Int {
    case Picture = 1001
    case Mention = 1002
    case Trend = 1003
    case Emoticon = 1004
    case Add = 1005
}

class ZCToolView: UIView {
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        backgroundColor = UIColor.greenColor()
        setUpUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    func setUpUI(){
        let picBut = addButton("compose_toolbar_picture", type: .Picture)
        let menBut = addButton("compose_mentionbutton_background", type: .Mention)
        let treBut = addButton("compose_trendbutton_background", type: .Trend)
        let emoBut = addButton("compose_emoticonbutton_background", type: .Emoticon)
        let addBut = addButton("compose_add_background", type: .Add)
        
        picBut.snp_makeConstraints { (make) in
            make.top.bottom.leading.equalTo(0)
        }
        
        menBut.snp_makeConstraints { (make) in
            make.top.bottom.equalTo(0)
            make.leading.equalTo(picBut.snp_trailing)
            make.width.equalTo(picBut)
        }
        
        treBut.snp_makeConstraints { (make) in
            make.top.bottom.equalTo(0)
            make.leading.equalTo(menBut.snp_trailing)
            make.width.equalTo(menBut)
        }
        
        emoBut.snp_makeConstraints { (make) in
            make.top.bottom.equalTo(0)
            make.leading.equalTo(treBut.snp_trailing)
            make.width.equalTo(treBut)
        }
        
        addBut.snp_makeConstraints { (make) in
            make.top.bottom.trailing.equalTo(0)
            make.leading.equalTo(emoBut.snp_trailing)
            make.width.equalTo(emoBut)
        }
        
    }
    
    
    func addButton(imgName: String, type: ZCToolViewButtonType) -> UIButton {
        let button = UIButton()
        button.tag = type.rawValue
        button.addTarget(self, action: #selector(ZCToolView.clickButton(_:)), forControlEvents: .TouchUpInside)
        button.setBackgroundImage(UIImage(named: "compose_toolbar_background"), forState: .Normal)
        button.setBackgroundImage(UIImage(named: "compose_toolbar_background"), forState: .Highlighted)
        button.setImage(UIImage(named:imgName), forState: .Normal)
        button.setImage(UIImage(named:"\(imgName)_highlighted"), forState: .Highlighted)
        addSubview(button)
        return button
    }
    
    var closure:((type: ZCToolViewButtonType)->())?
    
    func clickButton(button: UIButton) {
        
        closure?(type: ZCToolViewButtonType(rawValue: button.tag)!)
                
    }
    
    
}
